﻿/********************************************************************
	日期:2022/4/28 22:18
	名称:PECommon
	邮箱:yunnibbd@163.com
	作者:yunni
	描述:客户端服务端共用工具类
*********************************************************************/

using System;
using PENet;
using PEProtocol;

public enum LogType{
    Log = 0,
    Warning = 1,
    Error = 2,
    Info = 3
}

public class PECommon{
    public static void Log(string msg = "", LogType type = LogType.Log){
        LogLevel lv = (LogLevel) type;
        PETool.LogMsg(msg, lv);
    }

    public static int GetFightByProps(PlayerData pd){
        return pd.level * 100 + pd.ad + pd.ap + pd.addef + pd.apdef;
    }

    public static int GetPowerLimit(int level){
        return (level - 1) / 10 * 150 + 150;
    }

    public static int GetExpUpValByLevel(int level){
        return 100 * level * level;
    }

    public const int PowerAddSpace = 5; //分钟
    public const int PowerAddCount = 2;
    
    public static void CalcExp(PlayerData pd, int addExp){
        int curLevel = pd.level;
        int curExp = pd.exp;
        int addRestExp = addExp;
        while (true){
            int upNeedExp = PECommon.GetExpUpValByLevel(curLevel) - curExp;
            if (addRestExp >= upNeedExp){
                curLevel += 1;
                curExp = 0;
                addRestExp -= upNeedExp;
            }
            else{
                pd.level = curLevel;
                pd.exp = curExp + addRestExp;
                break;
            }
        }
    }
}
